/**
 * @author Anix
 */

import com.xvm.Logger;
import com.xvm.Utils;

/**
 * EquipmentLoader from config file
 * 
 */

class wot.hangar.AmmunitionPanel.AmmunitionPanel extends net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel

{
	
    function AmmunitionPanel() 
    {
        Utils.TraceXvmModule("AP_AmmunitionPanel");
		
        super();
    }
	    function configUI()
    {
        super.configUI();
        maitenanceBtn.addEventListener("press", this, "onShellClick");
        maitenanceBtn.addEventListener("rollOver", this, "showTooltip");
        maitenanceBtn.addEventListener("rollOut", this, "hideTooltip");
        maitenanceBtn.addEventListener("click", this, "hideTooltip");
        tuningBtn.addEventListener("press", this, "onTuningClick");
        tuningBtn.addEventListener("rollOver", this, "showTooltip");
        tuningBtn.addEventListener("rollOut", this, "hideTooltip");
        tuningBtn.addEventListener("click", this, "hideTooltip");
        for (var _loc3 = 0; _loc3 < net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.SHELLS_COUNT; ++_loc3)
        {
            var _loc4 = shells["shell" + _loc3 + "_mc"];
            _loc4.addEventListener("click", this, "onShellClick");
        } // end of for
        for (var _loc3 = 1; _loc3 < 4; ++_loc3)
        {
            equipments["equipment" + _loc3].select.addEventListener("click", this, "onShellClick");
        } // end of for
        gfx.io.GameDelegate.addCallBack("hangar.ammoResponse", this, "setAmmunitionValues");
        net.wargaming.Account.addCreditsCallBack(this, "setCredits");
        net.wargaming.Account.addGoldCallBack(this, "setGold");
    } // End of the function
    function showHelpLayout()
    {
        maitenanceBtn.showHelpLayout();
        if (tuningBtn._visible)
        {
            tuningBtn.showHelpLayout();
        } // end if
        modulesHelpLayout = net.wargaming.controls.HelpLayout.create(_root, {_borderWidth: modules.Radio._x + modules.Radio.select._width, _borderHeight: modules.Gun.select._height, _direction: "T", _text: "#lobby_help:hangar/modules", _x: 0, _y: 0}, modules);
        devicesHelpLayout = net.wargaming.controls.HelpLayout.create(_root, {_borderWidth: devices.optionalDevice3._x + devices.optionalDevice3.select._width, _borderHeight: devices.optionalDevice1.select._height, _direction: "B", _text: "#lobby_help:hangar/optional-devices", _x: 0, _y: 0}, devices);
    } // End of the function
    function closeHelpLayout()
    {
        maitenanceBtn.closeHelpLayout();
        tuningBtn.closeHelpLayout();
        net.wargaming.controls.HelpLayout.destroy(modulesHelpLayout);
        net.wargaming.controls.HelpLayout.destroy(devicesHelpLayout);
    } // End of the function
    function showTooltip(args)
    {
        var _loc2;
        if (args.target == maitenanceBtn)
        {
            _loc2 = "#tooltips:hangar/maintenance";
        }
        else if (args.target == tuningBtn)
        {
            _loc2 = "#tooltips:hangar/tuning";
        } // end else if
        net.wargaming.managers.ToolTipManager.__get__instance().showComplex(_loc2);
    } // End of the function
    function hideTolltip(args)
    {
        net.wargaming.managers.ToolTipManager.__get__instance().hide();
    } // End of the function
    function __setVehicleStatus(message, color)
    {
        vehicleStateMsg.text = message;
        var _loc2 = vehicleStateMsg.getTextFormat();
        _loc2.color = color;
        vehicleStateMsg.setTextFormat(_loc2);
    } // End of the function
    function setVehicleStatus(message, stateLevel)
    {
        lockMessage = net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.keyConv.convert(message);
        if (initialized && lockMessage.length > 0)
        {
            this.__setVehicleStatus(lockMessage, this.__stateLevelToColor(stateLevel));
        } // end if
    } // End of the function
    function setCredits()
    {
        credits = Number(arguments[0]);
        var _loc3 = net.wargaming.managers.WindowManager.__get__instance().getWindow("shellLoader");
        if (_loc3.form != undefined)
        {
            _loc3.form.changeCreditsValue(credits);
        } // end if
    } // End of the function
    function setGold()
    {
        gold = Number(arguments[0]);
        var _loc3 = net.wargaming.managers.WindowManager.__get__instance().getWindow("shellLoader");
        if (_loc3.form != undefined)
        {
            _loc3.form.changeGoldValue(credits);
        } // end if
    } // End of the function
    /*
	function onShellClick(event)
    {
        var _loc2 = net.wargaming.managers.WindowManager.__get__instance().getWindow("shellLoader");
        if (_loc2 != undefined)
        {
            net.wargaming.managers.WindowManager.__get__instance().swapToNextHighestDepth(_loc2);
            return;
        } // end if
        var _loc3 = {_title: "#menu:hangar/ammunitionPanel/technicalMaitenance/title", _allowResize: false, _formSource: "TechnicalMaitenance.swf", _formType: "swf", _offsetLeft: 13, _offsetRight: 9, _offsetTop: 34, _offsetBottom: 20};
        _loc2 = net.wargaming.managers.WindowManager.__get__instance().open("Window", "shellLoader", _loc3, true);
        _loc2.addEventListener("confirmFormComplete", function (event)
        {
            net.wargaming.managers.WindowManager.__get__instance().moveTo(event.target, Stage.width - event.width >> 1, Stage.height - event.height >> 1);
        });
        _loc2.addEventListener("close", this, "handleCloseWindow");
    } // End of the function 
	*/
    function onTuningClick(event)
    {
        tuningBtn.playSound("press");
        if (_root.loadCustomization)
        {
            _root.loadCustomization();
        } // end if
    } // End of the function
    function handleCloseWindow(event)
    {
        event.target.removeMovieClip();
    } // End of the function
    function disableAmmunitionPanel(value)
    {
        maitenanceBtn.__set__disabled(value);
        modules.setDisabled("ALL", value);
        devices.setDisabled("ALL", value);
        equipments.setDisabled("ALL", value);
    } // End of the function
    function disableTuningButton(value)
    {
        tuningBtn.__set__disabled(value);
    } // End of the function
    function setAmmunitionValues()
    {
        gunName = arguments.shift().toString();
        maxAmmo = Number(arguments.shift());
        var _loc23 = arguments.shift();
        var _loc22 = arguments.shift();
        var _loc24 = Number(arguments.shift());
        var _loc21 = arguments.shift();
        var _loc17 = arguments.shift();
        var _loc18 = arguments.shift();
        var _loc20 = arguments.shift();
        this.disableAmmunitionPanel(_loc17);
        loaded = 0;
        ammoArr = [];
        while (arguments.length != 0)
        {
            var _loc5 = {data: 1, id: arguments.shift(), type: arguments.shift(), icon: arguments.shift(), count: arguments.shift(), defaultCount: arguments.shift(), inventoryCount: arguments.shift(), price: arguments.shift(), currentcy: arguments.shift(), ammoName: arguments.shift(), tableName: arguments.shift()};
            ammoArr.push(_loc5);
            loaded = loaded + _loc5.count;
        } // end while
        this.__setVehicleStatus(_loc18, this.__stateLevelToColor(_loc20));
        var _loc19 = (_loc18 != "#menu:currentVehicleStatus/undamaged" && _loc18 != "#menu:currentVehicleStatus/crewNotFull" || loaded < maxAmmo * 0.200000) && !maitenanceBtn.__get__disabled();
        maitenanceBtn.flash._visible = _loc19;
        for (var _loc3 = 0; _loc3 < net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.SHELLS_COUNT; ++_loc3)
        {
            var _loc4 = shells["shell" + _loc3 + "_mc"];
            _loc4.onOut();
            _loc4.clear();
            _loc4.disabled = _loc17 || !ammoArr[_loc3];
            if (!ammoArr[_loc3])
            {
                continue;
            } // end if
            _loc4.current = _loc3;
            _loc4.id = ammoArr[_loc3].id;
            _loc4.shellType = ammoArr[_loc3].type;
            _loc4.shellIcon = ammoArr[_loc3].icon;
            _loc4.count = ammoArr[_loc3].count;
            _loc4.inventoryCount = ammoArr[_loc3].inventoryCount;
            _loc4.label = "#item_types:shell/kindsAbbreviation/" + ammoArr[_loc3].type;
        } // end of for
    } // End of the function
    function __stateLevelToColor(stateLevel)
    {
        switch (stateLevel)
        {
            case "info":
            {
                return (net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.GREEN_COLOR);
            } 
            case "warning":
            {
                return (net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.YELLOW_COLOR);
            } 
            case "critical":
            {
                return (net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.RED_COLOR);
            } 
        } // End of switch
        return (net.wargaming.hangar.AmmunitionPanel.AmmunitionPanel.GREEN_COLOR);
    } // End of the function
    
	
	var elements 
	
}

